package com.proxy.demo05;

/**
 * 强制代理模式:由真实角色GamePlayer指定自己的代理对象，而不能客户端给真是角色指定代理
 */
public class Client {
    public static void main(String[] args) {
        // 不能通过真实角色访问
//        testError();

        // 客户端指定代理也是不行的
//        testError2();

        testCase();
    }
    // 直接访问真实角色是不行的
    public static void testError(){
        IGamePlayer gamePlayer = new GamePlayer("张三");
        gamePlayer.login("zs","123456");
        gamePlayer.killBoss();
        gamePlayer.upgrade();
    }

    // 客户端不能给真实角色指定代理
    public static void testError2(){
        IGamePlayer gamePlayer = new GamePlayer("张三");
        GamePlayerProxy proxy = new GamePlayerProxy(gamePlayer);
        proxy.login("zs","123456");
        proxy.killBoss();
        proxy.upgrade();
    }

    public static void testCase(){
        IGamePlayer gamePlayer = new GamePlayer("张三");
        IGamePlayer proxy = gamePlayer.getProxy();
        proxy.login("zs","123456");
        proxy.killBoss();
        proxy.upgrade();
    }
}
